﻿using AppletReleaseTool.Configuration;
using AppletReleaseTool.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace AppletReleaseTool.EntityFrameworkCore
{
    /* This class is needed to run EF Core PMC commands. Not used anywhere else */
    public class AppletReleaseToolDbContextFactory : IDesignTimeDbContextFactory<AppletReleaseToolDbContext>
    {
        public AppletReleaseToolDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<AppletReleaseToolDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            DbContextOptionsConfigurer.Configure(
                builder,
                configuration.GetConnectionString(AppletReleaseToolConsts.ConnectionStringName)
            );

            return new AppletReleaseToolDbContext(builder.Options);
        }
    }
}